package com.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;

public class Start001 {

    static class t1 extends  Thread{
        @Override
        public void run() {
            System.out.println("t1 invoked...");
        }
    }

    static class t2 implements  Runnable{
        @Override
        public void run() {
            System.out.println("t2 invoked...");
        }
    }

    static class t3 implements Callable<String>{
        @Override
        public String call() throws Exception {
            System.out.println("t3 invoked...");
            return "success";
        }
    }
    public static void main(String[] args) {
        new Thread(new t1()).start();

        new Thread(new t2()).start();

        ExecutorService service = Executors.newCachedThreadPool();
        service.execute(()->{
            System.out.println("cache thread invoked...");
        });

        FutureTask<String> futureTask = new FutureTask<>(new t3());
        service.execute(futureTask);

        for(;;){
            if(futureTask.isDone()){
                System.out.println("is done...");
                break;
            }else{
                System.out.println("is not done");
            }
        }
        service.shutdown();
    }
}
